//
//  LuaP.hpp
//  LuaP
//
//  Created by liyong on 2016/10/18.
//  Copyright © 2016年 liyong. All rights reserved.
//

#ifndef LuaP_hpp
#define LuaP_hpp

#include <stdio.h>
extern "C" {
#include "src/lua.h"
#include "src/lauxlib.h"
#include "src/lualib.h"
}

#include <string>
#include <map>
#include <chrono>

using namespace std;

class FunctionCallInfo {
public:
    int numbers;
    chrono::steady_clock::time_point  startTime;
    double time;
};

class LuaP {
    
public:
    void SetLogPath(string path);
    
    void Start(lua_State *L);
    
    void WriteLog();
    
    void Stop();
    
    static LuaP &getInstance() {
        static LuaP luaP;
        return luaP;
    }
    void CallFunc(lua_Debug *);
private:
    string logPath;
    map<string, shared_ptr<FunctionCallInfo>> functionCalls;
    
};

extern "C" int luaopen_luaProfiler(lua_State *L);
#endif /* LuaP_hpp */
